package com.zzxy.service.impl;

import com.zzxy.mapper.NewspersonMapper;
import com.zzxy.entity.Newsperson;
import com.zzxy.service.NewspersonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Newsperson)表服务实现类
 *
 * @author makejava
 * @since 2023-11-28 10:51:08
 */
@Service("newspersonService")
public class NewspersonServiceImpl implements NewspersonService {
    @Resource
    private NewspersonMapper newspersonDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Newsperson queryById(Integer id) {
        return this.newspersonDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Newsperson> queryAllByLimit(int offset, int limit) {
        return this.newspersonDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param newsperson 实例对象
     * @return 实例对象
     */
    @Override
    public Newsperson insert(Newsperson newsperson) {
        this.newspersonDao.insert(newsperson);
        return newsperson;
    }

    /**
     * 修改数据
     *
     * @param newsperson 实例对象
     * @return 实例对象
     */
    @Override
    public Newsperson update(Newsperson newsperson) {
        this.newspersonDao.update(newsperson);
        return this.queryById(newsperson.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.newspersonDao.deleteById(id) > 0;
    }

    @Override
    public Newsperson login(String name, String password) {
        return newspersonDao.login(name,password);
    }
}